// pages/wmm/pdd_draw.js
const app = getApp();
var utilMd5 = require('../util/md5.js');
var WxParse = require('../../wxParse/wxParse.js');

Page({

    /**
     * 页面的初始数据
     */
    data: {
        max: '0',
        money: '',
        account: '',
        truename: '',
        articleMsg: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            max: app.globalData.balance_pdd,
            account: app.globalData.alipay_account,
            truename: app.globalData.truename,
            money: app.globalData.balance_pdd
        })
        this.getMsg()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },
    //获取文章内容
    getMsg() {
        var that = this;
        wx.request({
            url: app.globalData.api + '/app.php?c=Article&a=getArticleMsg',
            data: {
                article_id: 35,
            },
            header: {
                "Content-Type": "application/x-www-form-urlencoded",
                'platform': '' + app.globalData.platform,
                'version': '' + app.globalData.version,
            },
            method: 'POST',
            dataType: 'json',
            success: function (res) {
                console.log(res);
                if (res.data.code == 0) {
                    var article = res.data.data.article_msg.content;
                    WxParse.wxParse('article', 'html', article, that, 5);
                } else {
                    wx.showToast({
                        title: '' + res.data.msg,
                        icon: 'none',
                        duration: 1000
                    })
                }

            },
            fail: function () {

            }
        });
    },
    oninput: function (e) {
        this.setData({
            money: e.detail.value
        })
    },
    change: function () {
        wx.redirectTo({
            url: '/pages/mine/setting-bindaliay',
        })
    },
    tixian: function (e) {
        if (parseFloat(this.data.money.toString()) > parseFloat(app.globalData.balance_pdd.toString())) {
            wx.showToast({
                title: '超过最大提现金额',
                icon: 'none'
            })
            return;
        }
        var _this = this;
        var timestamp = Date.parse(new Date());
        var code = '999dmooohuikexiong999account' + this.data.account + 'account_type1data_typeJSONsign_typehkx.UserBalancePdd.drawmoney' + this.data.money + 'timestamp' + timestamp / 1000 + 'truename' + this.data.truename + 'token' + app.globalData.token + 'versionV1999dmooohuikexiong999';
        var MD5code = utilMd5.md5(code); //code需要加密的数据
        wx.request({
            url: app.globalData.api + '/app.php?c=UserBalancePdd&a=draw',
            data: {
                'token': app.globalData.token, //手机号码
                'data_type': 'JSON',
                'type': 'hkx.UserBalancePdd.draw',
                'account': this.data.account,
                'truename': this.data.truename,
                'account_type': '1',
                'money': this.data.money,
                'version': 'V1',
                'timestamp': timestamp / 1000,
                'sign': '' + MD5code.toUpperCase()
            },
            header: {
                "Content-Type": "application/x-www-form-urlencoded"
            },
            method: 'POST',
            dataType: 'json',
            success(res) {
                console.log(res)
                wx.showToast({
                    title: res.data.msg,
                    icon: 'none'
                })
                if (res.data.code == 0) {
                    setTimeout(() => {
                            wx.navigateBack({
                                delta: 0,
                            })
                            wx.navigateBack({
                                delta: 0,
                            })
                        },
                        200);

                }


            }
        })
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})